package com.ld.listener;

import com.ld.service.IPermissionScanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 第二部就是加上这个注解
 * 第三步是在启动类中加注解扫描这个包
 */
@WebListener
public class InitListener implements ServletContextListener {

    @Autowired
    private IPermissionScanService scanService;

    /**
     * 当tomcat一启动就执行该方法
     *
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {

//        WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext())
//                .getAutowireCapableBeanFactory().autowireBean(this);
        System.out.println("监听器启动");
        scanService.scan();
    }
}
